import request from '@/utils/request'
import { AxiosPromise } from 'axios'

interface GetQueryCourses {
    currentPage?: number
    pageSize?: number
    courseName?: string
    status?: number | null
}
const getQueryCourses = (data: GetQueryCourses): AxiosPromise<any> => {
  return request({
    method: 'POST',
    url: '/boss/course/getQueryCourses',
    data
  })
}

interface ChangeState {
    courseId: number
    status: number
}
const changeState = (data: ChangeState): AxiosPromise<any> => {
  return request({
    method: 'GET',
    url: '/boss/course/changeState',
    params: {
      ...data
    }
  })
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const imageUpdate = (data: any, onUploadProgress?: ((progressEvent: any) => void)): AxiosPromise<any> => {
  return request({
    method: 'POST',
    url: '/boss/course/upload',
    data,
    onUploadProgress
  })
}

export interface SaveOrUpdateCourseType {
    id?: number | null
    courseName?: string
    brief?: string
    teacherDTO?: {
        id?: number | null
        courseId?: number | null
        teacherName?: string
        teacherHeadPicUrl?: string
        position?: string
        description?: string
    }
    courseDescriptionMarkDown?: string
    price?: number
    discounts?: number
    priceTag?: string
    discountsTag?: string
    isNew?: boolean
    isNewDes?: string
    courseListImg?: string
    courseImgUrl: string
    sortNum?: number
    previewFirstField?: string
    previewSecondField?: string
    status?: number
    sales?: number
    activityCourse?: boolean
    activityCourseDTO?: {
        id?: number|null
        courseId?: number|null
        beginTime?: string
        endTime?: string
        amount?: number
        stock?: number
    }
    autoOnlineTime?: string
}
const saveOrUpdateCourse = (data: SaveOrUpdateCourseType): AxiosPromise<any> => {
  return request({
    method: 'POST',
    url: '/boss/course/saveOrUpdateCourse',
    data
  })
}

const getCourseById = (courseId: number|string): AxiosPromise<any> => {
  return request({
    method: 'GET',
    url: '/boss/course/getCourseById',
    params: {
      courseId
    }
  })
}

export {
  getQueryCourses,
  changeState,
  imageUpdate,
  saveOrUpdateCourse,
  getCourseById
}
